//
//  CZStatusBottomView.swift
//  GZWeibo007
//
//  Created by Apple on 15/12/21.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit
//代理方法
protocol CZStatusBottomViewDelegate: NSObjectProtocol {
//注册转发代理
 func ZFBtnClick()
//注册转发代理
 func PLBtnClick()
}

class CZStatusBottomView: UIView {
    
    var status: CZStatus? {
        didSet {
        setButton(forwardButton, count: status!.reposts_count)
        setButton(commentButton, count: status!.comments_count)
        setButton(zanButton, count: status!.attitudes_count)
        }
    
    
    }
    //MARK - 设置按钮
    private func setButton(button: UIButton,count: Int) {
        if count >= 10000 {
        let fimal = CGFloat(count) / 10000.0
            var titleText = String(format: ".1%f万", arguments: [fimal])
        titleText = titleText.stringByReplacingOccurrencesOfString(".0", withString: "")
        }
    button.setTitle("\(count)", forState: UIControlState.Normal)
    }
    
    weak var delegate: CZStatusBottomViewDelegate?
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 0.9, alpha: 1)
        
        // 准备UI
        prepareUI()
    }

    // MARK: - 准备UI
    private func prepareUI() {
        // 添加子控件
        addSubview(forwardButton)
        addSubview(commentButton)
        addSubview(zanButton)
        addSubview(separatorViewFirst)
        addSubview(separatorViewSecond)
        
        // 添加约束
        // 3个按钮水平平铺父控件
        self.ff_HorizontalTile([forwardButton, commentButton, zanButton], insets: UIEdgeInsetsZero)
        
        // 分割线1
        separatorViewFirst.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: forwardButton, size: nil)
        
        // 分割线2
        separatorViewSecond.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: commentButton, size: nil)
    }
//添加点击转发事件
    func ZFClick() {
    delegate?.ZFBtnClick()
    }
    //添加点击评论事件
    func PLClick() {
    delegate?.PLBtnClick()
    }
    // MARK: - 懒加载控件
    // 转发
    private lazy var forwardButton: UIButton = {
    let forwardButton = UIButton(imageName: "timeline_icon_retweet", fontSize: 11, title: "转发")
        forwardButton.addTarget(self, action: "ZFClick", forControlEvents: UIControlEvents.TouchUpInside)
    return forwardButton
    }()
    // 评论
    private lazy var commentButton: UIButton = {
    let commentButton = UIButton(imageName: "timeline_icon_comment", fontSize: 11, title: "评论")
        
    commentButton.addTarget(self, action: "PLClick", forControlEvents: UIControlEvents.TouchUpInside)
        return commentButton
    }()
    // 赞
    private lazy var zanButton: UIButton = UIButton(imageName: "timeline_icon_unlike", fontSize: 11, title: "赞")
    
    // 分割线1
    private lazy var separatorViewFirst: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
    
    // 分割线1
    private lazy var separatorViewSecond: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
    
}
